package com.qf.efserver.food.controller;

import com.qf.common.core.common.R;
import com.qf.common.core.entity.Nutrition;
import com.qf.efserver.food.VO.FoodVO;
import com.qf.efserver.food.VO.OleFood;
import com.qf.efserver.food.param.UserNutritionRecordsParam;
import com.qf.efserver.food.service.FoodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Nonnegative;
import javax.annotation.Resource;
import java.util.List;

/**
 * ---今日份---
 *
 * @Author Fzl
 * @Date 2024/11/8
 * @Desc 力未尽，不言降
 */
@Api(tags = "食物api")
@RestController
@RequestMapping("/food")
public class FoodController {

    @Resource
    private FoodService foodService;


    /**
     * 获取当天 食物页面的 碳水 脂肪 蛋白质
     * @return
     */
    @ApiOperation(value = "食物首页",
                notes = "根据token来查询用户当天的碳水，脂肪，蛋白质")
    @GetMapping("/selectAll")
    public R<List<FoodVO>> selectAll(){
        List<FoodVO> foodVOS = foodService.selectCFP();
        System.out.println("展示"+foodVOS);
        return R.ok(foodVOS);
    }


    @ApiOperation(value = "模糊查询",
                notes = "根据食物名字进行查询")
    @GetMapping("/selectFood")
    public R<List<Nutrition>> selectFood(String foodName){
        List<Nutrition> nutritions = foodService.selectShowByName(foodName);

        System.out.println("展示"+nutritions);
        return R.ok(nutritions);

    }

    @ApiOperation(value = "添加食物",
            notes = "首先模糊查询在进行添加")
    @PostMapping("/add")
    public R add(@RequestBody UserNutritionRecordsParam param){
        System.out.println("添加测试");
        foodService.addRecords(param);
        return R.ok();
    }

    @ApiOperation(value = "查询以前吃过的食物")
    @GetMapping("ole")
    public R<List<OleFood>> selectOle(){
        List<OleFood> oleFoods = foodService.selectOldFood();

        return R.ok(oleFoods);
    }

}
